<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <link rel="stylesheet" type="text/css" href="css/body.css"/>
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="js/js.js"></script>
</head>
<body>
<div class="container">
    <section id="content">
        <form action=""  >
            <h1>重置密码</h1>
                <input type="hidden" name="action" value="register">
                学生学号:<input type="text"  name="studentid" id="studentid" /><br/>
                身份证号:<input type="text" name="idnumber" id="idnumber" /><br/>
                学生手机:<input type="text" name="phone"  id="phone"/><br/>
                <button  type="button" onclick="resetPassword()">重置</button>
                <button  type="button" onclick="returnlogin()">返回</button>
        </form>
    </section>
</div>

<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<!--      <script src="./js/jquery-1.11.3.min.js"></script>-->
<script src="./js/sweetalert.min.js" type="text/javascript"></script>

<script>

    //返回登陆页面
    function returnlogin() {
        window.location.href = "./Login.html"
    }




    //学生学号的格式验证

    //失去焦点时自动匹配正确规范的学号
    $('#studentid').blur(function () {

        var studentid= $('#studentid').val()
        var namePatt=/[1-9][0-9]{10}/;

        if (studentid=="" || $.trim(studentid)==null || $.trim(studentid) ==''){



            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "学号不能为空！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });

        }else if (!namePatt.test(studentid)){

            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "学号码格式不正确，请仔细检查学号！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });
        }

    })



    //身份证号的格式验证
    $('#idnumber').blur(function () {


        var idnumber= $('#idnumber').val()
        var namePatt=/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;


        if (idnumber=="" || $.trim(idnumber)==null || $.trim(idnumber) ==''){


            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "身份证号不能为空！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });

        }else if (!namePatt.test(idnumber)){

            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "身份证号格式不正确！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });

        }


    })

    //学生手机号格式验证

    $('#phone').blur(function () {
        var phone= $('#phone').val()
        var namePatt=/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;


        if (phone=="" || $.trim(phone)==null || $.trim(phone) ==''){

            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "手机号不能为空！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });

        }else if (!namePatt.test(phone)){


            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "手机号格式不正确！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });
        }

    })



    //重置密码
    function resetPassword() {

        var studentid1= $('#studentid').val()
        var idnumber1= $('#idnumber').val()
        var phone1= $('#phone').val()




        //学号格式验证
        var namePatt1=/[1-9][0-9]{10}/;

        if (studentid1=="" || $.trim(studentid1)==null || $.trim(studentid1) ==''){

            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "学号不能为空！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });
                return false;

        }else if (!namePatt1.test(studentid1)){

            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "学号码格式不正确，请仔细检查学号！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });
                return false;
        }





        //身份证号格式验证
        var namePatt2=/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;

        if (idnumber1=="" || $.trim(idnumber1)==null || $.trim(idnumber1) ==''){



            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "身份证号不能为空！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });
            return false;
        }else if (!namePatt2.test(idnumber1)){

            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "身份证号格式不正确！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });
            return false;
        }







        //手机号格式验证
        var namePatt=/^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;


        if (phone1=="" || $.trim(phone1)==null || $.trim(phone1) ==''){

            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "手机号不能为空！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });

            return false;
        }else if (!namePatt.test(phone1)){

            swal({
                title : "重置密码提示信息",
                type : "error",
                text : "手机号格式不正确！",
                confirmButtonText : "确定",
                closeOnConfirm : false
            });

            return false;
        }



        $.ajax({
            //接收路径
            url: '../../student1/login.do',
            type: 'POST',
            dataType: 'text',
            data: {
                studentid:studentid1,
                idnumber:idnumber1,
                phone:phone1,
                action:'resetPassword'
            },
            success:function (data) {  //响应成功获取响应返回的值

                if (data==='0'){

                    swal({
                        title : "重置密码提示信息",
                        type : "error",
                        text : "密码重置失败，输入的身份证格式有误请检查后重新输入",
                        confirmButtonText : "确定",
                        closeOnConfirm : false
                    });

                }else if (data==='1'){

                    swal({
                        title : "重置密码提示信息",
                        type : "error",
                        text : "密码重置失败，学号、手机号、身份证号有误请检查后重新输入",
                        confirmButtonText : "确定",
                        closeOnConfirm : false
                    });

                }else if (data==='2'){

                    swal({
                        title : "重置密码提示信息",
                        type : "error",
                        text : "密码已被重置为qw123456初始密码，请重新登陆并修改密码",
                        confirmButtonText : "确定",
                        closeOnConfirm : false
                    }).then(function () {
                        //返回登陆页面
                        window.location.href = "./Login.html"
                    });

                }else {

                    swal({
                        title : "重置密码提示信息",
                        type : "error",
                        text : "重置密码失败",
                        confirmButtonText : "确定",
                        closeOnConfirm : false
                    });

                }
            },error: function (err) {  //响应失败
                swal({
                    title : "重置密码提示信息",
                    type : "error",
                    text : "重置密码失败",
                    confirmButtonText : "确定",
                    closeOnConfirm : false
                });

            }
        });


    }


</script>


</body>
</html>